package operation;

import book.Book;
import book.BookList;

import java.util.Scanner;

// 借阅图书
public class BorrowOperation implements IOperation{
    public void work(BookList bookList){
        System.out.println("借阅图书");
        System.out.println("请输入你想借阅的书籍名称：");
        Scanner sc = new Scanner(System.in);
        String name = sc.nextLine();
        for (int i = 0; i < bookList.getUsedSize(); i++) {
            Book book = bookList.getPos(i);
            if (name.equals(book.getName())){
                if(book.getBorrowed() ==  true){
                    System.out.println("你要借阅的书籍，已被借走。无法借阅。");
                    System.out.println("信息如下:");
                    System.out.println(book);
                    return;
                }
         // false 表示未借出，借出时，将 isBorrowed 置为true。表示借出成功
                book.setBorrowed(true);
                System.out.println("借阅成功！");
                System.out.println(book);
                return;
            }
        }
        System.out.println("没有你要借阅的书籍");
    }
}
